On Chrome, when you try to access a website and your internet is down, you see a little dinosaur. (Apparently because dinosaurs have short arms and they "can't reach" your website.
On this page, there is a hidden game, if you hit space bar you can play the T-rex run game.
Alternatively you can access the game directly here:
You goal today is to write a Python script to automate the playing of this game. Your program will look at the pixels on the screen to determine when it needs to hit the space bar and play the game automatically.
You can see what it looks like when the game is automated with a bot:
You might want to look up these two packages:
Reflection Time:
This is a place to journal your experience of completing this project. This will help you figure out how to improve as a developer.
Write down how you approached the project. What was hard, what was easy. How might you improve for the next project? What was your biggest learning from today? What would you do differently if you were to tackle this project again?
Reflection Time:
This is a place to journal your experience of completing this project. This will help you figure out how to improve as a developer.
Write down how you approached the project. What was hard, what was easy. How might you improve for the next project? What was your biggest learning from today? What would you do differently if you were to tackle this project again?
Approaching the Project: To automate the T-Rex Game, I started by researching and familiarizing myself with the game mechanics and how it can be controlled. I utilized Python packages like Pillow and PyAutoGUI to capture screenshots of the game window, analyze the pixel data to determine the game state, and simulate key presses to play the game automatically.
What was Hard: One of the challenges in this project was accurately detecting the game state based on pixel analysis. The game has various elements and states, such as the dinosaur, obstacles, and different background colors, which required careful observation and analysis of pixel values. Timing the key presses accurately to make the dinosaur jump over obstacles was also challenging, as it required synchronizing the script with the game's frame rate.
What was Easy: Capturing screenshots using Pillow and analyzing pixel values to determine the game state was relatively easy. Simulating key presses using PyAutoGUI to control the game was straightforward as well. The availability of the pyautogui.locateOnScreen() function made it convenient to detect game over screens and restart the game.
Areas for Improvement: For future automation projects, I can improve in the following areas:
Fine-tuning Pixel Analysis: Refining the pixel analysis process to improve accuracy and robustness. This can involve experimenting with different color thresholds, incorporating image processing techniques, or considering machine learning approaches for more complex scenarios.
Optimizing Timing and Actions: Implementing a more intelligent approach to timing the key presses and adjusting the dinosaur's actions. This can involve analyzing the game's frame rate, calculating optimal jump heights, or incorporating feedback mechanisms to adjust the gameplay dynamically.
Modularity and Configurability: Designing the automation script in a modular and configurable way, allowing easy adaptation to different versions or variations of the game. This can include separating the game logic from the control logic and providing configuration options for different game environments.
Biggest Learning: The biggest learning from this project was understanding the process of automating a game by analyzing pixels and simulating user inputs. It provided insights into the integration of computer vision techniques, user interface automation, and game mechanics. Additionally, it highlighted the importance of timing and synchronization when automating interactions with real-time applications.
What I Would Do Differently: If I were to tackle this project again, I would invest more time in fine-tuning the pixel analysis and timing mechanisms. This would help ensure more accurate detection of game elements and optimize the key presses for better gameplay. I would also explore additional approaches, such as machine learning or reinforcement learning, to create a more adaptive and intelligent bot for playing the T-Rex Game.
Overall, completing the project to automate the T-Rex Game provided hands-on experience in game automation and pixel analysis. Reflecting on the project helps identify areas for improvement and guides future endeavors in automating interactions with games and other graphical applications.
Give Feedback
What went well? What could be improved?
Reflection Time:
This is a place to journal your experience of completing this project. This will help you figure out how to improve as a developer.
Write down how you approached the project. What was hard, what was easy. How might you improve for the next project? What was your biggest learning from today? What would you do differently if you were to tackle this project again?
lll
Give Feedback
What went well? What could be improved?
Reflection Time:
This is a place to journal your experience of completing this project. This will help you figure out how to improve as a developer.
Write down how you approached the project. What was hard, what was easy. How might you improve for the next project? What was your biggest learning from today? What would you do differently if you were to tackle this project again?
- Defining Dino, Cactus and their movement.
- Grab image of cactus in black and white pixels.
- Jump Dino when the Black pixel dist is less than 40px.
- Scoring system for every jump.
- check for collision and action.
- Game Reset and Quit.
- Display Game over and Reset button.
Give Feedback
What went well? What could be improved?